package com.lsf.dunlian.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.amap.api.services.help.Tip;
import com.lsf.dunlian.R;
import com.lsf.dunlian.callback.ListClickCallback;
import com.lsf.dunlian.entity.AllNoticeRecordData;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MapSearchAddressRecyclerViewAdapter extends RecyclerView.Adapter<MapSearchAddressRecyclerViewAdapter.ViewHolder> {
    private List<Tip> mDataList;
    private Context context;
    private ListClickCallback clickCallback;

    public MapSearchAddressRecyclerViewAdapter(List<Tip> mDataList, Context context) {
        this.mDataList = mDataList;
        this.context = context;
    }

    public void setClickCallback(ListClickCallback clickCallback) {
        this.clickCallback = clickCallback;
    }

    @NonNull
    @Override
    public MapSearchAddressRecyclerViewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_search_address, parent, false);
        MapSearchAddressRecyclerViewAdapter.ViewHolder holder = new MapSearchAddressRecyclerViewAdapter.ViewHolder(view);
        return holder;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Tip data = mDataList.get(position);
        holder.address.setText(data.getAddress());
        holder.district.setText(data.getDistrict());
        holder.addressView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickCallback.click(data.getDistrict()+data.getAddress());
            }
        });

    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.address)
        TextView address;
        @BindView(R.id.district)
        TextView district;
        @BindView(R.id.addressView)
        LinearLayout addressView;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
